﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ScreenSQL
{
    public partial class frm_main : Form
    {
        public frm_main()
        {
            InitializeComponent();
        }

        private void btn_Screen_Click(object sender, EventArgs e)
        {
            string fileName = txt_file.Text.Trim();
            //按行读取为字符串数组
            List<string> newList1 = new List<string>();
            List<string> newList2 = new List<string>();
            string[] lines = System.IO.File.ReadAllLines(txt_old.Text.Trim() + @"\" + fileName + ".txt");
            foreach (var item in lines)
            {
                if (item.IndexOf("INSERT INTO") > 0 || item.IndexOf("UPDATE") > 0)
                {

                    if (item.IndexOf("INSERT INTO log") > 0)
                    {
                        newList1.Add(string.Format("{0}{1}", item.Replace("SQL =", ""), ";"));
                    }
                    else
                    {
                        newList2.Add(string.Format("{0}{1}", item.Replace("SQL =", ""), ";"));
                    }
                }
            }

            string[] newLines1 = newList1.ToArray();
            System.IO.File.WriteAllLines(txt_new.Text.Trim() + @"\" + fileName + @"_log.txt", newLines1, Encoding.UTF8);
            string[] newLines2 = newList2.ToArray();
            System.IO.File.WriteAllLines(txt_new.Text.Trim() + @"\" + fileName + @"_user.txt", newLines2, Encoding.UTF8);
        }
    }
}
